package com.sopragroup.dojo.webflow.trip;

import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Component;

@Component
public class TripService {

	private List<Trip> trips;
	
	public TripService() {
		trips = new ArrayList<Trip>();
		
		trips.add(new Trip("PARIS", 50));
		trips.add(new Trip("TOKYO", 1));
		trips.add(new Trip("LONDRES", 10));
		trips.add(new Trip("NEW YORK", 20));
		trips.add(new Trip("ROUEN", 2000));
	}

	public List<Trip> findByName(String city) {
		List<Trip> result = new ArrayList<Trip>();
		for (Trip trip : trips)
		{
			if (trip.getCity().contains(city.toUpperCase()))
			{
				result.add(trip);
			}
		}
		return result;
	}
	
	public Trip get(String city)
	{
		for (Trip trip : trips)
		{
			if (trip.getCity().equals(city))
			{
				return trip;
			}
		}
		
		return null;
	}
}
